---
title: "seasonality"
sidebarTitle: "seasonality"
---

`seasonality: day_of_week | hour_of_day | hour_of_week`

Some data sets have patterns that repeat over a time period, and are expected.
This is the normal behavior of these data sets.
This means that when we try to detect outliers from the normal and expected range, ignoring this patterns might cause false positives or make us miss anomalies.
The seasonality configuration is used to overcome this challenge and account for expected patterns.

**Supported seasonality configurations:**

- `day_of_week` - Uses the same day of week as a training set for each daily bucket (Compares Sunday to Sundays, Monday to Mondays, etc.).
- `hour_of_day` - Uses the same hour as a training set for each hourly bucket (For example will compare 10:00-11:00AM to 10:00-11:00AM on previous days, instead of any previous hour).
- `hour_of_week` - Uses the same hour and day of week as a training set for each hourly bucket (For example will compare 10:00-11:00AM on Sunday to 10:00-11:00AM on previous sundays).

**Example use case:**

Many data sets have lower volume over the weekend, and higher volume over the week days.
This means that the expected range for different days of the week is different.
The `day_of_week` seasonality uses the same day of week as a training set for each daily time bucket data point.
The expected range for Monday will be based on a training set of previous Mondays, and so on.

<br />
<br />

- _Default: none_
- _Supported values: `day_of_week`, `hour_of_day`, `hour_of_week`_
- _Relevant tests: Anomaly detection tests with `timestamp_column` and 1 day `time_bucket`_

#### How it works?

- The test will compare the value of a bucket to previous bucket with the same seasonality attribute, and not to the adjacent previous data points.
- The `training_period` of the test will be changed by default to assure a minimal training set. When `seasonality: day_of_week` is configured, `training_period` is by default multiplied by 7.


<Frame caption="seasonality change impact">
  <img
    src="https://res.cloudinary.com/diuctyblm/image/upload/v1681301380/Anomaly%20detection%20tests/seasonality_bz6gqp.png"
    alt="seasonality change impact"
  />
</Frame>

<RequestExample>

```yml test
models:
  - name: this_is_a_model
    tests:
      - elementary.volume_anomalies:
          seasonality: day_of_week
```

```yml model
models:
  - name: this_is_a_model
    config:
      elementary:
        seasonality: day_of_week
```

```yml dbt_project.yml
vars:
  seasonality: day_of_week
```

</RequestExample>
